﻿using UnityEngine;
using UnityEngine.UI;

public class InventoryButton : MonoBehaviour
{
    private Inventory inventory;

    private void Start()
    {
        // 尝试自动找到场景中的Inventory实例
        inventory = FindObjectOfType<Inventory>();
        if (inventory == null)
        {
            Debug.LogError("Inventory not found in the scene!");
        }

        Button button = GetComponent<Button>();
        button.onClick.AddListener(ToggleInventory);
    }

    // 添加一个方法来切换背包UI的可见性
    public void ToggleInventory()
    {
        if (inventory != null)
        {
            inventory.ToggleInventory();
        }
        else
        {
            Debug.LogError("Inventory is not set on InventoryButton!");
        }
    }
}
